home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / wiz.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  309 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. static struct rectangle spritevisiblearea =
  14. {
  15.     2*8, 32*8-1,
  16.     2*8, 30*8-1
  17. };
  18.  
  19. static struct rectangle spritevisibleareaflipx =
  20. {
  21.     0*8, 30*8-1,
  22.     2*8, 30*8-1
  23. };
  24.  
  25. unsigned char *wiz_videoram2;
  26. unsigned char *wiz_colorram2;
  27. unsigned char *wiz_attributesram;
  28. unsigned char *wiz_attributesram2;
  29.  
  30. static int flipx, flipy;
  31.  
  32. unsigned char *wiz_sprite_bank;
  33. static unsigned char char_bank[2];
  34. static unsigned char palbank[2];
  35. static int palette_bank;
  36.  
  37.  
  38. /***************************************************************************
  39.  
  40.   Convert the color PROMs into a more useable format.
  41.  
  42.   Stinger has three 256x4 palette PROMs (one per gun).
  43.   The palette PROMs are connected to the RGB output this way:
  44.  
  45.   bit 3 -- 100 ohm resistor  -- RED/GREEN/BLUE
  46.         -- 220 ohm resistor  -- RED/GREEN/BLUE
  47.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  48.   bit 0 -- 1  kohm resistor  -- RED/GREEN/BLUE
  49.  
  50. ***************************************************************************/
  51. void wiz_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  52. {
  53.     int i;
  54.  
  55.  
  56.     for (i = 0;i < Machine->drv->total_colors;i++)
  57.     {
  58.         int bit0,bit1,bit2,bit3;
  59.  
  60.  
  61.         bit0 = (color_prom[0] >> 0) & 0x01;
  62.         bit1 = (color_prom[0] >> 1) & 0x01;
  63.         bit2 = (color_prom[0] >> 2) & 0x01;
  64.         bit3 = (color_prom[0] >> 3) & 0x01;
  65.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  66.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  67.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  68.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  69.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  70.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  71.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  72.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  73.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  74.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  75.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  76.  
  77.         color_prom++;
  78.     }
  79. }
  80.  
  81. WRITE_HANDLER( wiz_attributes_w )
  82. {
  83.     if ((offset & 1) && wiz_attributesram[offset] != data)
  84.     {
  85.         int i;
  86.  
  87.  
  88.         for (i = offset / 2;i < videoram_size;i += 32)
  89.         {
  90.             dirtybuffer[i] = 1;
  91.         }
  92.     }
  93.  
  94.     wiz_attributesram[offset] = data;
  95. }
  96.  
  97. WRITE_HANDLER( wiz_palettebank_w )
  98. {
  99.     if (palbank[offset] != (data & 1))
  100.     {
  101.         palbank[offset] = data & 1;
  102.         palette_bank = palbank[0] + 2 * palbank[1];
  103.  
  104.         memset(dirtybuffer,1,videoram_size);
  105.     }
  106. }
  107.  
  108. WRITE_HANDLER( wiz_char_bank_select_w )
  109. {
  110.     if (char_bank[offset] != (data & 1))
  111.     {
  112.         char_bank[offset] = data & 1;
  113.         memset(dirtybuffer,1,videoram_size);
  114.     }
  115. }
  116.  
  117. WRITE_HANDLER( wiz_flipx_w )
  118. {
  119.     if (flipx != data)
  120.     {
  121.         flipx = data;
  122.  
  123.         memset(dirtybuffer, 1, videoram_size);
  124.     }
  125. }
  126.  
  127.  
  128. WRITE_HANDLER( wiz_flipy_w )
  129. {
  130.     if (flipy != data)
  131.     {
  132.         flipy = data;
  133.  
  134.         memset(dirtybuffer, 1, videoram_size);
  135.     }
  136. }
  137.  
  138. static void draw_background(struct osd_bitmap *bitmap, int bank, int colortype)
  139. {
  140.     int i,offs;
  141.  
  142.     /* for every character in the Video RAM, check if it has been modified */
  143.     /* since last time and update it accordingly. */
  144.  
  145.     for (offs = videoram_size - 1;offs >= 0;offs--)
  146.     {
  147.         if (dirtybuffer[offs])
  148.         {
  149.             int sx,sy,col;
  150.  
  151.             dirtybuffer[offs] = 0;
  152.  
  153.             sx = offs % 32;
  154.             sy = offs / 32;
  155.  
  156.             if (colortype)
  157.             {
  158.                 col = (wiz_attributesram[2 * sx + 1] & 0x07);
  159.             }
  160.             else
  161.             {
  162.                 col = (colorram[offs] & 0x07);
  163.             }
  164.  
  165.             if (flipx) sx = 31 - sx;
  166.             if (flipy) sy = 31 - sy;
  167.  
  168.             drawgfx(tmpbitmap,Machine->gfx[bank],
  169.                 videoram[offs],
  170.                 (wiz_attributesram[2 * (offs % 32) + 1] & 0x07) + 8 * palette_bank,
  171.                 flipx,flipy,
  172.                 8*sx,8*sy,
  173.                 0,TRANSPARENCY_NONE,0);
  174.         }
  175.     }
  176.  
  177.     /* copy the temporary bitmap to the screen */
  178.     {
  179.         int scroll[32];
  180.  
  181.  
  182.         if (flipx)
  183.         {
  184.             for (i = 0;i < 32;i++)
  185.             {
  186.                 scroll[31-i] = -wiz_attributesram[2 * i];
  187.                 if (flipy) scroll[31-i] = -scroll[31-i];
  188.             }
  189.         }
  190.         else
  191.         {
  192.             for (i = 0;i < 32;i++)
  193.             {
  194.                 scroll[i] = -wiz_attributesram[2 * i];
  195.                 if (flipy) scroll[i] = -scroll[i];
  196.             }
  197.         }
  198.  
  199.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  200.  
  201.     }
  202. }
  203.  
  204. static void draw_foreground(struct osd_bitmap *bitmap, int colortype)
  205. {
  206.     int offs;
  207.  
  208.     /* draw the frontmost playfield. They are characters, but draw them as sprites. */
  209.     for (offs = videoram_size - 1;offs >= 0;offs--)
  210.     {
  211.         int scroll,sx,sy,col;
  212.  
  213.  
  214.         sx = offs % 32;
  215.         sy = offs / 32;
  216.  
  217.         if (colortype)
  218.         {
  219.             col = (wiz_attributesram2[2 * sx + 1] & 0x07);
  220.         }
  221.         else
  222.         {
  223.             col = (wiz_colorram2[offs] & 0x07);
  224.         }
  225.  
  226.         scroll = (8*sy + 256 - wiz_attributesram2[2 * sx]) % 256;
  227.         if (flipy)
  228.         {
  229.            scroll = (248 - scroll) % 256;
  230.         }
  231.         if (flipx) sx = 31 - sx;
  232.  
  233.  
  234.         drawgfx(bitmap,Machine->gfx[char_bank[1]],
  235.             wiz_videoram2[offs],
  236.             col + 8 * palette_bank,
  237.             flipx,flipy,
  238.             8*sx,scroll,
  239.             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  240.     }
  241. }
  242.  
  243. static void draw_sprites(struct osd_bitmap *bitmap, unsigned char* sprite_ram,
  244.                          int bank, const struct rectangle* visible_area)
  245. {
  246.     int offs;
  247.  
  248.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  249.     {
  250.         int sx,sy;
  251.  
  252.  
  253.         sx = sprite_ram[offs + 3];
  254.         sy = sprite_ram[offs];
  255.  
  256.         if (!sx || !sy) continue;
  257.  
  258.         if ( flipx) sx = 240 - sx;
  259.         if (!flipy) sy = 240 - sy;
  260.  
  261.         drawgfx(bitmap,Machine->gfx[bank],
  262.                 sprite_ram[offs + 1],
  263.                 (sprite_ram[offs + 2] & 0x07) + 8 * palette_bank,
  264.                 flipx,flipy,
  265.                 sx,sy,
  266.                 visible_area,TRANSPARENCY_PEN,0);
  267.     }
  268. }
  269.  
  270. /***************************************************************************
  271.  
  272.   Draw the game screen in the given osd_bitmap.
  273.   Do NOT call osd_update_display() from this function, it will be called by
  274.   the main emulation engine.
  275.  
  276. ***************************************************************************/
  277. void wiz_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  278. {
  279.     int bank;
  280.     const struct rectangle* visible_area;
  281.  
  282.     draw_background(bitmap, 2 + ((char_bank[0] << 1) | char_bank[1]), 0);
  283.     draw_foreground(bitmap, 0);
  284.  
  285.     visible_area = flipx ? &spritevisibleareaflipx : &spritevisiblearea;
  286.  
  287.     /* I seriously doubt that the real hardware works this way */
  288.     if ((spriteram[1] & 0x80) || !spriteram[3] || !spriteram[0])
  289.     {
  290.         bank = 7 + *wiz_sprite_bank;
  291.     }
  292.     else
  293.     {
  294.         bank = 8;    // Dragon boss
  295.     }
  296.  
  297.     draw_sprites(bitmap, spriteram_2, 6,    visible_area);
  298.     draw_sprites(bitmap, spriteram  , bank, visible_area);
  299. }
  300.  
  301.  
  302. void stinger_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  303. {
  304.     draw_background(bitmap, 2 + char_bank[0], 1);
  305.     draw_foreground(bitmap, 1);
  306.     draw_sprites(bitmap, spriteram_2, 4, &Machine->drv->visible_area);
  307.     draw_sprites(bitmap, spriteram  , 5, &Machine->drv->visible_area);
  308. }
  309.